package com.hcb.tonguetiphealth.widget.bookOnline;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.hcb.tonguetiphealth.adapter.DishOrderListAdapter;
import com.hcb.tonguetiphealth.global.Global;
import com.hcb.tonguetiphealth.view.R;
import com.hcb.tonguetiphealth.widget.BottomWidget;
import com.hcb.tonguetiphealth.widget.GeneralWidget;

public class DishOrderWidget extends GeneralWidget implements OnClickListener {
	private static final String TAG = "dishOrderWidget";
	
	private Activity ctx;
	private Button btCommit;
	private ListView dishOrderListView;
	private LinearLayout llBack;
	
	public DishOrderWidget(Context context) {
		super(context);
		ctx = (Activity)context;
		inflate(context, R.layout.dish_order, this); 
		new BottomWidget(ctx, this);
		bindView();
		bindEvent();
		initData();
	}
	
 

	private void bindEvent() {

		dishOrderListView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
//				ResDish dish = (ResDish) arg0.getAdapter().getItem(arg2);
//				ctx.getIntent().putExtra("dishId", dish.getId());
//				ctx.getIntent().putExtra("resId", userid);
//				ctx.getIntent().putExtra("FromWidgetFlag", "onlineBook");
//				System.out.println("dish:"+dish.getTitle());
////				Global.resList = resList; 
//				ctx.setContentView(new DishInfoWidget(ctx));
			}
		});
		
	 
 	
	}
	
	private void bindView() {
	
		llBack = (LinearLayout)findViewById(R.id.dish_order_back);
		btCommit = (Button)findViewById(R.id.dish_order_ok_button);
		dishOrderListView = (ListView)findViewById(R.id.dish_order_listview);
		
		llBack.setOnClickListener(this);
		btCommit.setOnClickListener(this);
	}
	
	public void initData(){
		
		setAdapter();
	}
 
	
	public void onClick(View v) {
		switch(v.getId()) {
		 
		case R.id.dish_order_back:
			ctx.finish();
			break;
		case R.id.dish_order_ok_button:
			if (Global.resDishOrderList.size()>0) {
				ctx.setContentView(new DishOrderMsgOkWidget(ctx));
			}else {
				showMessage(ctx, "尚未预订任何菜品！");
			}
			break;
		default:
			break;
		}
	}
 
	public void setAdapter(){
		DishOrderListAdapter adapter =  new DishOrderListAdapter(this, ctx, Global.resDishOrderList);
		dishOrderListView.setAdapter(adapter);
	}

	@Override
	public void notifyAdapter() {
		// TODO Auto-generated method stub
		
	}
 
	
}
